package com.panasonic.web.controller.exam;

import com.panasonic.common.annotation.Log;
import com.panasonic.common.core.controller.BaseController;
import com.panasonic.common.core.domain.AjaxResult;
import com.panasonic.common.core.page.TableDataInfo;
import com.panasonic.common.enums.BusinessType;
import com.panasonic.web.domain.cms.CmsExam;
import com.panasonic.web.service.ICmsExamService;
import com.panasonic.web.vo.CmsExamReviewParameter;
import com.panasonic.web.vo.CmsExamReviewVo;
import com.panasonic.web.vo.ExamineeInfo;
import com.panasonic.web.vo.ExamineeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 考试信息Controller
 *
 * @author lwf
 * @date 2021-11-16
 */
@RestController
@RequestMapping("/cms/exam")
@Api(value = "CmsExam", tags = "考试信息")
public class CmsExamController extends BaseController {
    @Autowired
    private ICmsExamService cmsExamService;

    /**
     * 查询考试信息列表
     */
    @ApiOperation(value = "查询")
    @GetMapping("/list")
    public TableDataInfo list(CmsExam cmsExam) {
        startPage();
        System.out.println(cmsExam.getExamStatus());
        List<CmsExam> list = cmsExamService.selectCmsExamList(cmsExam);
        return getDataTable(list);
    }



    /**
     * 获取考试信息详细信息
     */
    @ApiOperation(value = "获取考试信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(cmsExamService.selectCmsExamById(id));
    }

    /**
     * 新增考试信息
     */
    @ApiOperation(value = "新增考试信息")
    @Log(title = "考试信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsExam cmsExam) {
        Long id = cmsExamService.insertCmsExam(cmsExam);
        return AjaxResult.success(id);
    }

    /**
     * 修改考试信息
     */
    @ApiOperation(value = "修改考试信息")
    @Log(title = "考试信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsExam cmsExam) {
        return toAjax(cmsExamService.updateCmsExam(cmsExam));
    }

    /**
     * 删除考试信息
     */
    @ApiOperation(value = "删除考试信息")
    @Log(title = "考试信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cmsExamService.deleteCmsExamByIds(ids));
    }

    @ApiOperation(value = "获取批阅列表")
    @GetMapping("/getReviewList/{examId}")
    public AjaxResult getReviewList(@PathVariable long examId, CmsExamReviewParameter parameter) {
        parameter.setExamId(examId);
        List<CmsExamReviewVo> list = cmsExamService.getReviewList(parameter);
        return AjaxResult.success(list);
    }

    @ApiOperation(value = "设置考试考生")
    @PostMapping("/saveExaminees")
    public AjaxResult saveExaminees(@RequestBody ExamineeVo examineeVo) {
        cmsExamService.saveExaminees(examineeVo);
        return AjaxResult.success();
    }
    @ApiOperation(value = "获取考生")
    @GetMapping("/getExaminees/{examId}")
    public AjaxResult getExaminees(@PathVariable long examId) {

        List<ExamineeInfo> list = cmsExamService.getExaminees(examId);
        return AjaxResult.success(list);
    }
}
